import 'dart:io';

import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_syt/datas/message_model.dart';
import 'package:flutter_syt/utils/web_socket_utility.dart';

class ServiceMessagesVideo extends StatefulWidget {
  final MessageModel model;

  final ChewieController? chewieController;
  ServiceMessagesVideo({required this.model, this.chewieController});
  @override
  ServiceMessagesVideoState createState() => ServiceMessagesVideoState();
}

class ServiceMessagesVideoState extends State<ServiceMessagesVideo> {
  // Uint8List? thumbnaildata;
//  String? thumbnailPath;
  @override
  Widget build(BuildContext context) {
    return Container(
        width: 240.w,
        height: 120.w,
        child: Stack(
          children: [
            Positioned.fill(
              child: ClipRRect(
                borderRadius: widget.model.direction == MessageDirection.RECEIVE
                    ? BorderRadius.only(
                        bottomLeft: Radius.circular(12),
                        bottomRight: Radius.circular(12),
                        topRight: Radius.circular(12))
                    : BorderRadius.only(
                        bottomLeft: Radius.circular(12),
                        bottomRight: Radius.circular(12),
                        topLeft: Radius.circular(12)),
                child: (widget.chewieController != null &&
                        widget.chewieController!.videoPlayerController.value
                            .isInitialized)
                    ? Chewie(
                        controller: widget.chewieController!,
                      )
                    : widget.model.videoImagePath != null
                        ? Image.file(
                            File(widget.model.videoImagePath!),
                            fit: BoxFit.fitWidth,
                          )
                        : Container(),
              ),
            ),
            Positioned.fill(
                child: Visibility(
              visible: !(widget.chewieController != null &&
                  widget.chewieController!.videoPlayerController.value
                      .isInitialized),
              child: Icon(
                Icons.play_circle,
                size: 50,
                color: Colors.white,
              ),
            ))
          ],
        ));
  }

  @override
  void initState() {
    super.initState();
    // getVideoThumbn();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void didUpdateWidget(ServiceMessagesVideo oldWidget) {
    super.didUpdateWidget(oldWidget);
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }
}
